/*******************************
*******************************/
#include "pvd.h"

u8 PVDFlag=0;
u8 outageFlg=0; 

/**
 * @brief  Configures EXTI Lines.
 */
void PVD_EXTI_Configuration(void)
{
    EXTI_InitType EXTI_InitStructure;

    /* Configure EXTI Line16(PVD Output) to generate an interrupt on rising and
       falling edges */
    EXTI_ClrITPendBit(EXTI_LINE16);
    EXTI_InitStructure.EXTI_Line    = EXTI_LINE16;
    EXTI_InitStructure.EXTI_Mode    = EXTI_Mode_Interrupt;
    EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising_Falling;
    EXTI_InitStructure.EXTI_LineCmd = ENABLE;
    EXTI_InitPeripheral(&EXTI_InitStructure);
}

/**
 * @brief  Configures NVIC and Vector Table base location.
 */
void PVD_NVIC_Configuration(void)
{
    NVIC_InitType NVIC_InitStructure;

    /* Configure one bit for preemption priority */
    NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);

    /* Enable the PVD Interrupt */
    NVIC_InitStructure.NVIC_IRQChannel                   = PVD_IRQn;
    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
    NVIC_InitStructure.NVIC_IRQChannelSubPriority        = 0;
    NVIC_InitStructure.NVIC_IRQChannelCmd                = ENABLE;
    NVIC_Init(&NVIC_InitStructure);
}

void PVD_Init(u32 PVDLevel)
{
    /* Enable PWR and BKP clock */
    RCC_EnableAPB1PeriphClk(RCC_APB1_PERIPH_PWR, ENABLE);
    /* Configure one bit for preemption priority */
    PVD_EXTI_Configuration();

    /* Enable the PVD Interrupt */
    PVD_NVIC_Configuration();
    
     /* Configure the PVD Level to  */
    PWR_PVDLevelConfig(PVDLevel);

    PWR_PvdEnable(ENABLE);
}

void PVD_run_tack(void)
{   
    uint8_t pwr_state = 0;
    
    pwr_state = PWR_GetFlagStatus(0,PWR_PVDO_FLAG);

}


